{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b4d6090b-1ef9-4c30-b544-276592bf35bc",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from jupyter_clickable_image_widget import ClickableImageWidget"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1e4f45cd-cad5-4664-917d-ed62a8457be0",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "image_widget = ClickableImageWidget()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "83fe8e6e-6911-46a8-a643-1e99b75e1fdc",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "def on_message(_, content, ignore):\n",
    "    if content['event'] == 'click':\n",
    "        data = content['eventData']\n",
    "        alt_key = data['altKey']\n",
    "        ctrl_key = data['ctrlKey']\n",
    "        shift_key = data['shiftKey']\n",
    "        x = data['offsetX']\n",
    "        y = data['offsetY']\n",
    "        print(x, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c9516c25-0785-44ae-832f-4c658136b398",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "image_widget.on_msg(on_message)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "7f4ac649-5c60-4e29-8cde-34a269c88489",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "file = open(\"JetsonOrin-DevKit-Back_1024x768.jpg\", \"rb\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "4247ae28-eb52-49e8-8ba3-989cb519f1c3",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "image = file.read()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f453d1aa-af08-4d7d-ab4b-6854467e77e1",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "image_widget.value = image"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "306a81c0-6719-4388-bbb2-7164380c24ea",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d8ea8b9d529e4b6bb69d84e87e9d55bf",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "ClickableImageWidget(value=b'\\xff\\xd8\\xff\\xe1\\x00\\xbcExif\\x00\\x00II*\\x00\\x08\\x00\\x00\\x00\\x06\\x00\\x12\\x01\\x03\\x…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(image_widget)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6e0424cc-ad65-4e11-8ece-c563b25e3814",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
